package signGrammar.expressions.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import signGrammar.expressions.IGrammarExpression;

public class CProductionsMap {
	private Map<String, List<IGrammarExpression> > patternMap;
	
	public CProductionsMap() {
		patternMap = new LinkedHashMap<String, List<IGrammarExpression>>();
	}
	
	public CProductionsMap addExpr(String key, IGrammarExpression expressionPattern){
		if(!patternMap.containsKey( key ) )
			patternMap.put(key, new ArrayList<IGrammarExpression>());
		patternMap.get(key).add(expressionPattern);
		return this;
	}
	
	public IGrammarExpression[] get(String key){
		List<IGrammarExpression> list = patternMap.get(key);
		return list.toArray( new IGrammarExpression[ list.size() ] );
	}
	
	public String[] getKeys(){
		Set<String> components = patternMap.keySet();
		return components.toArray(new String[ components.size() ]);
	}
	
	public CProductionsMap clear(){
		patternMap.clear();
		return this;
	}
}
